﻿using System;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Collections.ObjectModel;

namespace PIT.Labs.ProjectRepository.WebParts.ListRandomizerWebPart.ListRandomizerWebPart
{
    /// <summary>
    /// Manages the randomizes values.
    /// </summary>
    public static class Randomizer
    {
        /// <summary>
        /// Generates some randomized numbers.
        /// </summary>
        /// <param name="itemCount">The highest number.</param>
        /// <param name="maxItemCount">The count of how many numbers are returned.</param>
        /// <returns>
        /// <see cref="Collection&lt;T&gt;"/><br/>
        /// A collection of <see cref="int"/> containing the randomized values.
        /// </returns>
        public static Collection<int> Shuffle(int itemCount, int maxItemCount)
        {
            if (itemCount < 0)
                throw new ArgumentException("Value must be greater than 0 or equal to 0", "itemCount");
            if (maxItemCount < 0)
                throw new ArgumentException("Value must be greater than 0 or equal to 0", "maxItemCount");

            Collection<int> numbers = new Collection<int>();
            if (maxItemCount > itemCount)
                maxItemCount = itemCount;
            while (numbers.Count < maxItemCount)
            {
                Random r = new Random();
                int randomInt = r.Next(itemCount);
                if (!numbers.Contains(randomInt))
                    numbers.Add(randomInt);
            }
            return numbers;
        }

    }
}
